//
//  ErrorMessage.m
//  RequestTest
//
//  Created by xntech on 13-8-20.
//  Copyright (c) 2013年 xntech. All rights reserved.
//

#import "ErrorMessage.h"
#import "SynthesizeSingleton.h"
#import "UIFoundationPrefix.h"


#define DefaultErrorFile  @"error.plist"
@interface DefaultMessage : NSObject
{
     NSDictionary  *errorDic;
}
- (NSDictionary *)errorDic;
+ (DefaultMessage *)sharedDefaultMessage;
@end

@implementation DefaultMessage
SYNTHESIZE_SINGLETON_FOR_CLASS(DefaultMessage)
- (id)init
{
    self = [super init];
    if (self)
    {
        errorDic = [[NSDictionary alloc] initWithContentsOfFile:UIResourceFile(DefaultErrorFile)];
    }
    return self;
}
- (NSDictionary *)errorDic
{
    return errorDic;
}
@end

@interface ErrorMessage()
@property (nonatomic,retain)NSDictionary   *errorDic;
@end

@implementation ErrorMessage
@synthesize errorDic = _errorDic;
+ (ErrorMessage *)defaultError
{
    ErrorMessage *errorMessage = [[[ErrorMessage alloc] init] autorelease];
    [errorMessage setErrorDic:[[DefaultMessage sharedDefaultMessage] errorDic]];
    return errorMessage;
}
- (id)initWithPlist:(NSString *)path
{
    self = [super init];
    if (self)
    {
        self.errorDic = [NSDictionary dictionaryWithContentsOfFile:path];
    }
    return self;
}
- (NSString *)errorMessage:(int)code
{
    return [self.errorDic objectForKey:[[NSNumber numberWithInt:code] description]];
}
- (NSString *)description
{
    return [_errorDic description];
}
- (void)dealloc
{
    [_errorDic release];
    [super dealloc];
}
@end
